🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / datastore / src / commonMain / kotlin / org / meshtastic / core / datastore / ChannelSetDataSource.kt
Displaying Raw • Download
core/datastore/src/commonMain/kotlin/org/meshtastic/core/datastore/ChannelSetDataSource.kt cea2c3a015c2c3227f13a3ac9bc4e13c35bbd4ee (cea2c3a0) Text, 2.85 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.datastore
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.catch
Tff7b72import T7ee787okio.IOException
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.datastore.di.CoreChannelSetDataStore
Tff7b72import T7ee787org.meshtastic.proto.Channel
Tff7b72import T7ee787org.meshtastic.proto.ChannelSet
Tff7b72import T7ee787org.meshtastic.proto.ChannelSettings
Tff7b72import T7ee787org.meshtastic.proto.Config
T8b949e/** Class that handles saving and retrieving [ChannelSet] data. */
Tf0883e@Single
Tff7b72class T56d364ChannelSetDataSourceTb4b4b4(Tff7b72private Tff7b72val Te6edf3channelSetStoreTb4b4b4: Te6edf3CoreChannelSetDataStoreTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3channelSetFlowTb4b4b4: Te6edf3FlowTff7b72<Te6edf3ChannelSetTff7b72> Tff7b72=
Te6edf3channelSetStoreTb4b4b4.Te6edf3dataTb4b4b4.Te6edf3catch Tb4b4b4{ Te6edf3exception Tff7b72-Tff7b72>
T8b949e// dataStore.data throws an IOException when an error is encountered when reading data
Tff7b72if Tb4b4b4(Te6edf3exception Tff7b72is Te6edf3IOExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3e Tb4b4b4{ Ta5d6ff"Ta5d6ffError reading DeviceConfig settings: Tffd700${Te6edf3exceptionTb4b4b4.Te6edf3messageTffd700}Ta5d6ff" Tb4b4b4}
Te6edf3emitTb4b4b4(Te6edf3ChannelSetTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Tff7b72throw Te6edf3exception
Tb4b4b4}
Tb4b4b4}
Tff7b72suspend Tff7b72fun Td2a8ffclearChannelSetTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3channelSetStoreTb4b4b4.Te6edf3updateData Tb4b4b4{ Te6edf3ChannelSetTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4}
T8b949e/** Replaces all [ChannelSettings] in a single atomic operation. */
Tff7b72suspend Tff7b72fun Td2a8ffreplaceAllSettingsTb4b4b4(Te6edf3settingsListTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4) Tb4b4b4{
Te6edf3channelSetStoreTb4b4b4.Te6edf3updateData Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3settings Tff7b72= Te6edf3settingsListTb4b4b4) Tb4b4b4}
Tb4b4b4}
T8b949e/** Updates the [ChannelSettings] list with the provided channel. */
Tff7b72suspend Tff7b72fun Td2a8ffupdateChannelSettingsTb4b4b4(Te6edf3channelTb4b4b4: Te6edf3ChannelTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3channelTb4b4b4.Te6edf3role Tff7b72=Tff7b72= Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3DISABLEDTb4b4b4) Tff7b72return
Te6edf3channelSetStoreTb4b4b4.Te6edf3updateData Tb4b4b4{ Te6edf3preference Tff7b72-Tff7b72>
Tff7b72val Te6edf3settings Tff7b72= Te6edf3preferenceTb4b4b4.Te6edf3settingsTb4b4b4.Te6edf3toMutableListTb4b4b4(Tb4b4b4)
T8b949e// Resize to fit channel
Tff7b72while Tb4b4b4(Te6edf3settingsTb4b4b4.Te6edf3size Tff7b72<Tff7b72= Te6edf3channelTb4b4b4.Te6edf3indexTb4b4b4) Tb4b4b4{
Te6edf3settingsTb4b4b4.Te6edf3addTb4b4b4(Te6edf3ChannelSettingsTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
T8b949e// use setSettings() to ensure settingsList and channel indexes match
Te6edf3settingsTff7b72[Te6edf3channelTb4b4b4.Te6edf3indexTff7b72] Tff7b72= Te6edf3channelTb4b4b4.Te6edf3settings Tff7b72?: Te6edf3ChannelSettingsTb4b4b4(Tb4b4b4)
Te6edf3preferenceTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3settings Tff7b72= Te6edf3settingsTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tff7b72suspend Tff7b72fun Td2a8ffsetLoraConfigTb4b4b4(Te6edf3configTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4) Tb4b4b4{
Te6edf3channelSetStoreTb4b4b4.Te6edf3updateData Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3copyTb4b4b4(Te6edf3lora_config Tff7b72= Te6edf3configTb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s